

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>3.1. Coordinate fitting and alignment — MDAnalysis.analysis.align &mdash; MDAnalysis v0.7.5-devel documentation</title>
    <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.7.5-devel',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within MDAnalysis v0.7.5-devel documentation"
          href="../../_static/opensearch.xml"/>
    <link rel="shortcut icon" href="../../_static/mdanalysis-logo.ico"/>
    <link rel="top" title="MDAnalysis v0.7.5-devel documentation" href="../../index.html" />
    <link rel="up" title="3. Analysis modules" href="../analysis_modules.html" />
    <link rel="next" title="3.2. Native contacts analysis — MDAnalysis.analysis.contacts" href="contacts.html" />
    <link rel="prev" title="3. Analysis modules" href="../analysis_modules.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="contacts.html" title="3.2. Native contacts analysis — MDAnalysis.analysis.contacts"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="../analysis_modules.html" title="3. Analysis modules"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">MDAnalysis v0.7.5-devel documentation</a> &raquo;</li>
          <li><a href="../analysis_modules.html" accesskey="U">3. Analysis modules</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/mdanalysis-logo-200x150.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">3.1. Coordinate fitting and alignment &#8212; <tt class="docutils literal"><span class="pre">MDAnalysis.analysis.align</span></tt></a><ul>
<li><a class="reference internal" href="#rms-fitting-tutorial">3.1.1. RMS-fitting tutorial</a></li>
<li><a class="reference internal" href="#common-usage">3.1.2. Common usage</a></li>
<li><a class="reference internal" href="#functions">3.1.3. Functions</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="../analysis_modules.html"
                        title="previous chapter">3. Analysis modules</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="contacts.html"
                        title="next chapter">3.2. Native contacts analysis &#8212; <tt class="docutils literal"><span class="pre">MDAnalysis.analysis.contacts</span></tt></a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/documentation_pages/analysis/align.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <span class="target" id="module-MDAnalysis.analysis.align"></span><div class="section" id="coordinate-fitting-and-alignment-mdanalysis-analysis-align">
<h1>3.1. Coordinate fitting and alignment &#8212; <a class="reference internal" href="#module-MDAnalysis.analysis.align" title="MDAnalysis.analysis.align"><tt class="xref py py-mod docutils literal"><span class="pre">MDAnalysis.analysis.align</span></tt></a><a class="headerlink" href="#coordinate-fitting-and-alignment-mdanalysis-analysis-align" title="Permalink to this headline">¶</a></h1>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Author:</th><td class="field-body">Oliver Beckstein, Joshua Adelman</td>
</tr>
<tr class="field"><th class="field-name">Year:</th><td class="field-body">2010&#8211;2011</td>
</tr>
<tr class="field"><th class="field-name">Copyright:</th><td class="field-body">GNU Public License v3</td>
</tr>
</tbody>
</table>
<p>The module contains functions to fit a target structure to a reference
structure. They use the fast QCP algorithm to calculate the root mean
square distance (RMSD) between two coordinate sets and the rotation
matrix <em>R</em> that minimizes the RMSD.</p>
<p>Typically, one selects a group of atoms (such as the C-alphas),
calculate the RMSD and transformation matrix, and apply the
transformation to the current frame of a trajectory to obtain the
rotated structure. The <a class="reference internal" href="#MDAnalysis.analysis.align.alignto" title="MDAnalysis.analysis.align.alignto"><tt class="xref py py-func docutils literal"><span class="pre">alignto()</span></tt></a> and <a class="reference internal" href="#MDAnalysis.analysis.align.rms_fit_trj" title="MDAnalysis.analysis.align.rms_fit_trj"><tt class="xref py py-func docutils literal"><span class="pre">rms_fit_trj()</span></tt></a>
functions can be used to do this for individual frames and
trajectories respectively.</p>
<p>The RMS-fitting tutorial below shows how to do the individual steps
manually and explains the intermediate steps.</p>
<div class="section" id="rms-fitting-tutorial">
<h2>3.1.1. RMS-fitting tutorial<a class="headerlink" href="#rms-fitting-tutorial" title="Permalink to this headline">¶</a></h2>
<p>The example uses files provided as part of the MDAnalysis test suite
(in the variables <tt class="xref py py-data docutils literal"><span class="pre">PSF</span></tt>,
<tt class="xref py py-data docutils literal"><span class="pre">DCD</span></tt>, and
<tt class="xref py py-data docutils literal"><span class="pre">PDB_small</span></tt>). For all further
examples execute first</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">MDAnalysis</span> <span class="kn">import</span> <span class="o">*</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">MDAnalysis.analysis.align</span> <span class="kn">import</span> <span class="o">*</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">MDAnalysis.tests.datafiles</span> <span class="kn">import</span> <span class="n">PSF</span><span class="p">,</span> <span class="n">DCD</span><span class="p">,</span> <span class="n">PDB_small</span>
</pre></div>
</div>
<p>In the simplest case, we can simply calculate the C-alpha RMSD between
two structures, using <a class="reference internal" href="#MDAnalysis.analysis.align.rmsd" title="MDAnalysis.analysis.align.rmsd"><tt class="xref py py-func docutils literal"><span class="pre">rmsd()</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ref</span> <span class="o">=</span> <span class="n">Universe</span><span class="p">(</span><span class="n">PDB_small</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mobile</span> <span class="o">=</span> <span class="n">Universe</span><span class="p">(</span><span class="n">PSF</span><span class="p">,</span><span class="n">DCD</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rmsd</span><span class="p">(</span><span class="n">mobile</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">CA</span><span class="o">.</span><span class="n">coordinates</span><span class="p">(),</span> <span class="n">ref</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">CA</span><span class="o">.</span><span class="n">coordinates</span><span class="p">())</span>
<span class="go">18.858259026820352</span>
</pre></div>
</div>
<p>Note that in this example translations have not been removed. In order
to look at the pure rotation one needs to superimpose the centres of
mass (or geometry) first:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ref0</span> <span class="o">=</span>  <span class="n">ref</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">CA</span><span class="o">.</span><span class="n">coordinates</span><span class="p">()</span> <span class="o">-</span> <span class="n">ref</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">CA</span><span class="o">.</span><span class="n">centerOfMass</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mobile0</span> <span class="o">=</span>  <span class="n">mobile</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">CA</span><span class="o">.</span><span class="n">coordinates</span><span class="p">()</span> <span class="o">-</span> <span class="n">mobile</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">CA</span><span class="o">.</span><span class="n">centerOfMass</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rmsd</span><span class="p">(</span><span class="n">mobile0</span><span class="p">,</span> <span class="n">ref0</span><span class="p">)</span>
<span class="go"> 6.8093965864717951</span>
</pre></div>
</div>
<p>The rotation matrix that superimposes <em>mobile</em> on <em>ref</em> while
minimizing the CA-RMSD is obtained with the <a class="reference internal" href="#MDAnalysis.analysis.align.rotation_matrix" title="MDAnalysis.analysis.align.rotation_matrix"><tt class="xref py py-func docutils literal"><span class="pre">rotation_matrix()</span></tt></a>
function</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">R</span><span class="p">,</span> <span class="n">rmsd</span> <span class="o">=</span> <span class="n">rotation_matrix</span><span class="p">(</span><span class="n">mobile0</span><span class="p">,</span> <span class="n">ref0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">rmsd</span>
<span class="go">6.8093965864717951</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">R</span>
<span class="go">[[ 0.14514539 -0.27259113  0.95111876]</span>
<span class="go"> [ 0.88652593  0.46267112 -0.00268642]</span>
<span class="go"> [-0.43932289  0.84358136  0.30881368]]</span>
</pre></div>
</div>
<p>Putting all this together one can superimpose all of <em>mobile</em> onto <em>ref</em>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">mobile</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="o">-</span><span class="n">mobile</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">CA</span><span class="o">.</span><span class="n">centerOfMass</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mobile</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">rotate</span><span class="p">(</span><span class="n">R</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mobile</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="n">ref</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">CA</span><span class="o">.</span><span class="n">centerOfMass</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mobile</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;mobile_on_ref.pdb&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="common-usage">
<h2>3.1.2. Common usage<a class="headerlink" href="#common-usage" title="Permalink to this headline">¶</a></h2>
<p>To <strong>fit a single structure</strong> with <a class="reference internal" href="#MDAnalysis.analysis.align.alignto" title="MDAnalysis.analysis.align.alignto"><tt class="xref py py-func docutils literal"><span class="pre">alignto()</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ref</span> <span class="o">=</span> <span class="n">Universe</span><span class="p">(</span><span class="n">PSF</span><span class="p">,</span> <span class="n">PDB_small</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mobile</span> <span class="o">=</span> <span class="n">Universe</span><span class="p">(</span><span class="n">PSF</span><span class="p">,</span> <span class="n">DCD</span><span class="p">)</span>     <span class="c"># we use the first frame</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">alignto</span><span class="p">(</span><span class="n">mobile</span><span class="p">,</span> <span class="n">ref</span><span class="p">,</span> <span class="n">select</span><span class="o">=</span><span class="s">&quot;protein and name CA&quot;</span><span class="p">,</span> <span class="n">mass_weighted</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<p>This will change <em>all</em> coordinates in <em>mobile</em> so that the protein
C-alpha atoms are optimally superimposed (translation and rotation).</p>
<p>To <strong>fit a whole trajectory</strong> to a reference structure with the
<a class="reference internal" href="#MDAnalysis.analysis.align.rms_fit_trj" title="MDAnalysis.analysis.align.rms_fit_trj"><tt class="xref py py-func docutils literal"><span class="pre">rms_fit_trj()</span></tt></a> function:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ref</span> <span class="o">=</span> <span class="n">Universe</span><span class="p">(</span><span class="n">PSF</span><span class="p">,</span> <span class="n">PDB_small</span><span class="p">)</span>   <span class="c"># reference structure 1AKE</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">trj</span> <span class="o">=</span> <span class="n">Universe</span><span class="p">(</span><span class="n">PSF</span><span class="p">,</span> <span class="n">DCD</span><span class="p">)</span>         <span class="c"># trajectory of change 1AKE-&gt;4AKE</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rms_fit_trj</span><span class="p">(</span><span class="n">trj</span><span class="p">,</span> <span class="n">ref</span><span class="p">,</span> <span class="n">filename</span><span class="o">=</span><span class="s">&#39;rmsfit.dcd&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>It is also possible to align two arbitrary structures by providing a
mapping between atoms based on a sequence alignment. This allows
fitting of structural homologs or wild type and mutant.</p>
<p>If a alignment was provided as &#8220;sequences.aln&#8221; one would first produce
the appropriate MDAnalysis selections with the <a class="reference internal" href="#MDAnalysis.analysis.align.fasta2select" title="MDAnalysis.analysis.align.fasta2select"><tt class="xref py py-func docutils literal"><span class="pre">fasta2select()</span></tt></a>
function and then feed the resulting dictionary to <a class="reference internal" href="#MDAnalysis.analysis.align.rms_fit_trj" title="MDAnalysis.analysis.align.rms_fit_trj"><tt class="xref py py-func docutils literal"><span class="pre">rms_fit_trj()</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">seldict</span> <span class="o">=</span> <span class="n">fasta2select</span><span class="p">(</span><span class="s">&#39;sequences.aln&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rms_fit_trj</span><span class="p">(</span><span class="n">trj</span><span class="p">,</span> <span class="n">ref</span><span class="p">,</span> <span class="n">filename</span><span class="o">=</span><span class="s">&#39;rmsfit.dcd&#39;</span><span class="p">,</span> <span class="n">select</span><span class="o">=</span><span class="n">seldict</span><span class="p">)</span>
</pre></div>
</div>
<p>(See the documentation of the functions for this advanced usage.)</p>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="../core/qcprot.html#module-MDAnalysis.core.qcprot" title="MDAnalysis.core.qcprot"><tt class="xref py py-mod docutils literal"><span class="pre">MDAnalysis.core.qcprot</span></tt></a> for the fast RMSD algorithm.</p>
</div>
</div>
<div class="section" id="functions">
<h2>3.1.3. Functions<a class="headerlink" href="#functions" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="MDAnalysis.analysis.align.alignto">
<tt class="descclassname">MDAnalysis.analysis.align.</tt><tt class="descname">alignto</tt><big>(</big><em>mobile</em>, <em>reference</em>, <em>select='all'</em>, <em>mass_weighted=False</em>, <em>subselection=None</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.align.alignto" title="Permalink to this definition">¶</a></dt>
<dd><p>Spatially align <em>mobile</em> to <em>reference</em> by doing a RMSD fit on <em>select</em> atoms.</p>
<p>The superposition is done in the following way:</p>
<ol class="arabic simple">
<li>A rotation matrix is computed that minimizes the RMSD between
the coordinates of <cite>mobile.selectAtoms(sel1)</cite> and
<cite>reference.selectAtoms(sel2)</cite>; before the rotation, <em>mobile</em> is
translated so that its center of geometry (or center of mass)
coincides with the one of <em>reference</em>. (See below for explanation of
how <em>sel1</em> and <em>sel2</em> are derived from <em>select</em>.)</li>
<li>All atoms in <a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.Universe" title="MDAnalysis.core.AtomGroup.Universe"><tt class="xref py py-class docutils literal"><span class="pre">Universe</span></tt></a> that
contains <em>mobile</em> are shifted and rotated. (See below for how
to change this behavior through the <em>subselection</em> keyword.)</li>
</ol>
<p>The <em>mobile</em> and <em>reference</em> atom groups can be constructed so that they
already match atom by atom. In this case, <em>select</em> should be set to &#8220;all&#8221;
(or <tt class="xref docutils literal"><span class="pre">None</span></tt>) so that no further selections are applied to <em>mobile</em> and
<em>reference</em>, therefore preserving the exact atom ordering (see
<a class="reference internal" href="../selections.html#ordered-selections-label"><em>Ordered selections</em></a>).</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">The atom order for <em>mobile</em> and <em>reference</em> is <em>only</em>
preserved when <em>select</em> is either &#8220;all&#8221; or <tt class="xref docutils literal"><span class="pre">None</span></tt>. In any other case,
a new selection will be made that will sort the resulting AtomGroup by
index and therefore destroy the correspondence between the two groups. <strong>It
is safest not to mix ordered AtomGroups with selection strings.</strong></p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Arguments :</th><td class="field-body"><dl class="first docutils">
<dt><em>mobile</em></dt>
<dd><p class="first last">structure to be aligned, a <a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.AtomGroup" title="MDAnalysis.core.AtomGroup.AtomGroup"><tt class="xref py py-class docutils literal"><span class="pre">AtomGroup</span></tt></a>
or a whole <a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.Universe" title="MDAnalysis.core.AtomGroup.Universe"><tt class="xref py py-class docutils literal"><span class="pre">Universe</span></tt></a></p>
</dd>
<dt><em>reference</em></dt>
<dd><p class="first last">reference structure, a <a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.AtomGroup" title="MDAnalysis.core.AtomGroup.AtomGroup"><tt class="xref py py-class docutils literal"><span class="pre">AtomGroup</span></tt></a>
or a whole <a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.Universe" title="MDAnalysis.core.AtomGroup.Universe"><tt class="xref py py-class docutils literal"><span class="pre">Universe</span></tt></a></p>
</dd>
<dt><em>select</em></dt>
<dd><ol class="first arabic simple">
<li>any valid selection string for
<a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.AtomGroup.selectAtoms" title="MDAnalysis.core.AtomGroup.AtomGroup.selectAtoms"><tt class="xref py py-meth docutils literal"><span class="pre">selectAtoms()</span></tt></a> that produces identical
selections in <em>mobile</em> and <em>reference</em>; or</li>
<li>dictionary <tt class="docutils literal"><span class="pre">{'mobile':sel1,</span> <span class="pre">'reference':sel2}</span></tt>.
(the <a class="reference internal" href="#MDAnalysis.analysis.align.fasta2select" title="MDAnalysis.analysis.align.fasta2select"><tt class="xref py py-func docutils literal"><span class="pre">fasta2select()</span></tt></a> function returns such a
dictionary based on a <a class="reference external" href="http://www.clustal.org/">ClustalW</a> or <a class="reference external" href="http://www.compbio.dundee.ac.uk/manuals/stamp.4.2/">STAMP</a> sequence alignment); or</li>
<li>tuple <tt class="docutils literal"><span class="pre">(sel1,</span> <span class="pre">sel2)</span></tt></li>
</ol>
<p class="last">When using 2. or 3. with <em>sel1</em> and <em>sel2</em> then these selections can also each be
a list of selection strings (to generate a AtomGroup with defined atom order as
described under <a class="reference internal" href="../selections.html#ordered-selections-label"><em>Ordered selections</em></a>).</p>
</dd>
<dt><em>mass_weighted</em> <span class="classifier-delimiter">:</span> <span class="classifier">boolean</span></dt>
<dd><p class="first last"><tt class="xref docutils literal"><span class="pre">True</span></tt> uses the masses <tt class="xref py py-meth docutils literal"><span class="pre">reference.masses()</span></tt> as weights for the
RMSD fit.</p>
</dd>
<dt><em>subselection</em></dt>
<dd><p class="first">Apply the transformation only to this selection.</p>
<dl class="last docutils">
<dt><tt class="xref docutils literal"><span class="pre">None</span></tt> [default]</dt>
<dd><p class="first last">Apply to <cite>mobile.universe.atoms</cite> (i.e. all atoms in the
context of the selection from <em>mobile</em> such as the rest of a
protein, ligands and the surrounding water)</p>
</dd>
<dt><em>selection-string</em></dt>
<dd><p class="first last">Apply to <cite>mobile.selectAtoms(selection-string)</cite></p>
</dd>
<dt><a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.AtomGroup" title="MDAnalysis.core.AtomGroup.AtomGroup"><tt class="xref py py-class docutils literal"><span class="pre">AtomGroup</span></tt></a></dt>
<dd><p class="first last">Apply to the arbitrary group of atoms</p>
</dd>
</dl>
</dd>
</dl>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last">RMSD before and after spatial alignment.</p>
</td>
</tr>
</tbody>
</table>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">For RMSD-fitting trajectories it is more efficient to
use <a class="reference internal" href="#MDAnalysis.analysis.align.rms_fit_trj" title="MDAnalysis.analysis.align.rms_fit_trj"><tt class="xref py py-func docutils literal"><span class="pre">rms_fit_trj()</span></tt></a>.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.analysis.align.fasta2select">
<tt class="descclassname">MDAnalysis.analysis.align.</tt><tt class="descname">fasta2select</tt><big>(</big><em>fastafilename</em>, <em>is_aligned=False</em>, <em>ref_resids=None</em>, <em>target_resids=None</em>, <em>ref_offset=0</em>, <em>target_offset=0</em>, <em>verbosity=3</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.align.fasta2select" title="Permalink to this definition">¶</a></dt>
<dd><p>Return selection strings that will select equivalent residues.</p>
<p>The function aligns two sequences provided in a FASTA file and
constructs MDAnalysis selection strings of the common atoms. When
these two strings are applied to the two different proteins they
will generate AtomGroups of the aligned residues.</p>
<p><em>fastafilename</em> contains the two un-aligned sequences in FASTA
format. The reference is assumed to be the first sequence, the
target the second. <a class="reference external" href="http://www.clustal.org/">ClustalW</a> produces a pairwise
alignment (which is written to a file with suffix .aln).  The
output contains atom selection strings that select the same atoms
in the two structures.</p>
<p>Unless <em>ref_offset</em> and/or <em>target_offset</em> are specified, the resids
in the structure are assumed to correspond to the positions in the
un-aligned sequence, namely the first residue has resid == 1.</p>
<p>In more complicated cases (e.g. when the resid numbering in the
structure/psf has gaps due to missing parts), simply provide the
sequence of resids as they appear in the psf in <em>ref_resids</em> or
<em>target_resids</em>, e.g.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">target_resids</span> <span class="o">=</span> <span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">resid</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">trj</span><span class="o">.</span><span class="n">selectAtoms</span><span class="p">(</span><span class="s">&#39;name CA&#39;</span><span class="p">)]</span>
</pre></div>
</div>
<p>(This translation table <em>is</em> combined with any value for <em>xxx_offset</em>!)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Arguments :</th><td class="field-body"><dl class="first docutils">
<dt><em>fastafilename</em></dt>
<dd><p class="first last">FASTA file with first sequence as reference and
second the one to be aligned (ORDER IS IMPORTANT!)</p>
</dd>
<dt><em>is_aligned</em></dt>
<dd><p class="first last">False: run clustalw for sequence alignment; True: use
the alignment in the file (e.g. from STAMP)</p>
</dd>
<dt><em>ref_offset</em></dt>
<dd><p class="first last">add this number to the column number in the FASTA file
to get the original residue number</p>
</dd>
<dt><em>target_offset</em></dt>
<dd><p class="first last">same for the target</p>
</dd>
<dt><em>ref_resids</em></dt>
<dd><p class="first last">sequence of resids as they appear in the reference structure</p>
</dd>
<dt><em>target_resids</em></dt>
<dd><p class="first last">sequence of resids as they appear in the target</p>
</dd>
</dl>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><dl class="first last docutils">
<dt><em>select_dict</em></dt>
<dd><p class="first last">dictionary with &#8216;reference&#8217; and &#8216;mobile&#8217; selection string
that can be used immediately in <a class="reference internal" href="#MDAnalysis.analysis.align.rms_fit_trj" title="MDAnalysis.analysis.align.rms_fit_trj"><tt class="xref py py-func docutils literal"><span class="pre">rms_fit_trj()</span></tt></a> as
<tt class="docutils literal"><span class="pre">select=select_dict</span></tt>.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.analysis.align.rms_fit_trj">
<tt class="descclassname">MDAnalysis.analysis.align.</tt><tt class="descname">rms_fit_trj</tt><big>(</big><em>traj</em>, <em>reference</em>, <em>select='all'</em>, <em>filename=None</em>, <em>rmsdfile=None</em>, <em>prefix='rmsfit_'</em>, <em>mass_weighted=False</em>, <em>tol_mass=0.10000000000000001</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.align.rms_fit_trj" title="Permalink to this definition">¶</a></dt>
<dd><p>RMS-fit trajectory to a reference structure using a selection.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Arguments :</th><td class="field-body"><dl class="first last docutils">
<dt><em>traj</em></dt>
<dd><p class="first last">trajectory, <tt class="xref py py-class docutils literal"><span class="pre">MDAnalysis.Universe</span></tt> object</p>
</dd>
<dt><em>reference</em></dt>
<dd><p class="first last">reference coordinates; <tt class="xref py py-class docutils literal"><span class="pre">MDAnalysis.Universe</span></tt> object
(uses the current time step of the object)</p>
</dd>
<dt><em>select</em></dt>
<dd><ol class="first arabic simple">
<li>any valid selection string for
<a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.AtomGroup.selectAtoms" title="MDAnalysis.core.AtomGroup.AtomGroup.selectAtoms"><tt class="xref py py-meth docutils literal"><span class="pre">selectAtoms()</span></tt></a> that produces identical
selections in <em>mobile</em> and <em>reference</em>; or</li>
<li>a dictionary <tt class="docutils literal"><span class="pre">{'mobile':sel1,</span> <span class="pre">'reference':sel2}</span></tt> (the
<a class="reference internal" href="#MDAnalysis.analysis.align.fasta2select" title="MDAnalysis.analysis.align.fasta2select"><tt class="xref py py-func docutils literal"><span class="pre">fasta2select()</span></tt></a> function returns such a
dictionary based on a <a class="reference external" href="http://www.clustal.org/">ClustalW</a> or <a class="reference external" href="http://www.compbio.dundee.ac.uk/manuals/stamp.4.2/">STAMP</a> sequence alignment); or</li>
<li>a tuple <tt class="docutils literal"><span class="pre">(sel1,</span> <span class="pre">sel2)</span></tt></li>
</ol>
<p class="last">When using 2. or 3. with <em>sel1</em> and <em>sel2</em> then these selections can also each be
a list of selection strings (to generate a AtomGroup with defined atom order as
described under <a class="reference internal" href="../selections.html#ordered-selections-label"><em>Ordered selections</em></a>).</p>
</dd>
<dt><em>filename</em></dt>
<dd><p class="first last">file name for the RMS-fitted trajectory or pdb; defaults to the
original trajectory filename (from <em>traj</em>) with <em>prefix</em> prepended</p>
</dd>
<dt><em>rmsdfile</em></dt>
<dd><p class="first last">file name for writing the RMSD timeseries [<tt class="xref docutils literal"><span class="pre">None</span></tt>]</p>
</dd>
<dt><em>prefix</em></dt>
<dd><p class="first last">prefix for autogenerating the new output filename</p>
</dd>
<dt><em>mass_weighted</em></dt>
<dd><p class="first last">do a mass-weighted RMSD fit</p>
</dd>
<dt><em>tol_mass</em></dt>
<dd><p class="first last">Reject match if the atomic masses for matched atoms differ by more than
<em>tol_mass</em> [0.1]</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<p>Both reference and trajectory must be <tt class="xref py py-class docutils literal"><span class="pre">MDAnalysis.Universe</span></tt>
instances. If they contain a trajectory then it is used. The
output file format is the same as the input <em>traj</em>.</p>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.analysis.align.rmsd">
<tt class="descclassname">MDAnalysis.analysis.align.</tt><tt class="descname">rmsd</tt><big>(</big><em>a</em>, <em>b</em>, <em>weights=None</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.align.rmsd" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns RMSD between two coordinate sets <em>a</em> and <em>b</em>.</p>
<p><em>a</em> and <em>b</em> are arrays of the coordinates of N atoms of shape N*3
as generated by, e.g.,
<a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.AtomGroup.coordinates" title="MDAnalysis.core.AtomGroup.AtomGroup.coordinates"><tt class="xref py py-meth docutils literal"><span class="pre">MDAnalysis.core.AtomGroup.AtomGroup.coordinates()</span></tt></a>.</p>
<p>The <em>weights</em> can be an array of length N, containing e.g. masses
for a weighted RMSD calculation.</p>
<dl class="docutils">
<dt>Example::</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">u</span> <span class="o">=</span> <span class="n">Universe</span><span class="p">(</span><span class="n">PSF</span><span class="p">,</span><span class="n">DCD</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bb</span> <span class="o">=</span> <span class="n">u</span><span class="o">.</span><span class="n">selectAtoms</span><span class="p">(</span><span class="s">&#39;backbone&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">bb</span><span class="o">.</span><span class="n">coordinates</span><span class="p">()</span>  <span class="c"># coordinates of first frame</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">u</span><span class="o">.</span><span class="n">trajectory</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>      <span class="c"># forward to last frame</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">B</span> <span class="o">=</span> <span class="n">bb</span><span class="o">.</span><span class="n">coordinates</span><span class="p">()</span>  <span class="c"># coordinates of last frame</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rmsd</span><span class="p">(</span><span class="n">A</span><span class="p">,</span><span class="n">B</span><span class="p">)</span>
<span class="go">6.8342494129169804</span>
</pre></div>
</div>
</dd>
</dl>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.analysis.align.rotation_matrix">
<tt class="descclassname">MDAnalysis.analysis.align.</tt><tt class="descname">rotation_matrix</tt><big>(</big><em>a</em>, <em>b</em>, <em>weights=None</em><big>)</big><a class="headerlink" href="#MDAnalysis.analysis.align.rotation_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the 3x3 rotation matrix for RMSD fitting coordinate sets <em>a</em> and <em>b</em>.</p>
<p>The rotation matrix <em>R</em> transforms <em>a</em> to overlap with <em>b</em> (i.e. <em>b</em> is the
reference structure):</p>
<blockquote>
<div><em>b</em> = <em>R</em> . <em>a</em></div></blockquote>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Arguments :</th><td class="field-body"><dl class="first docutils">
<dt><em>a</em></dt>
<dd><p class="first last">coordinates that are to be rotated (&#8220;mobile set&#8221;); array of N atoms
of shape N*3 as generated by, e.g.,
<a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.AtomGroup.coordinates" title="MDAnalysis.core.AtomGroup.AtomGroup.coordinates"><tt class="xref py py-meth docutils literal"><span class="pre">MDAnalysis.core.AtomGroup.AtomGroup.coordinates()</span></tt></a>.</p>
</dd>
<dt><em>b</em></dt>
<dd><p class="first last">reference coordinates; array of N atoms of shape N*3 as generated by,
e.g., <a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.AtomGroup.coordinates" title="MDAnalysis.core.AtomGroup.AtomGroup.coordinates"><tt class="xref py py-meth docutils literal"><span class="pre">MDAnalysis.core.AtomGroup.AtomGroup.coordinates()</span></tt></a>.</p>
</dd>
<dt><em>weights</em></dt>
<dd><p class="first last">array of floats of size N for doing weighted RMSD fitting (e.g. the
masses of the atoms)</p>
</dd>
</dl>
</td>
</tr>
<tr class="field"><th class="field-name">Returns :</th><td class="field-body"><p class="first last"><tt class="docutils literal"><span class="pre">(R,</span> <span class="pre">rmsd)</span></tt> rmsd and rotation matrix <em>R</em></p>
</td>
</tr>
</tbody>
</table>
<p><em>R</em> can be used as an argument for
<a class="reference internal" href="../core/AtomGroup.html#MDAnalysis.core.AtomGroup.AtomGroup.rotate" title="MDAnalysis.core.AtomGroup.AtomGroup.rotate"><tt class="xref py py-meth docutils literal"><span class="pre">MDAnalysis.core.AtomGroup.AtomGroup.rotate()</span></tt></a> to generate a rotated
selection, e.g.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">R</span> <span class="o">=</span> <span class="n">rotation_matrix</span><span class="p">(</span><span class="n">A</span><span class="o">.</span><span class="n">selectAtoms</span><span class="p">(</span><span class="s">&#39;backbone&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">coordinates</span><span class="p">(),</span> <span class="n">B</span><span class="o">.</span><span class="n">selectAtoms</span><span class="p">(</span><span class="s">&#39;backbone&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">coordinates</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">rotate</span><span class="p">(</span><span class="n">R</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;rotated.pdb&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that the function does <em>not</em> shift the centers of mass or geometry;
this needs to be done by the user.</p>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#MDAnalysis.analysis.align.rmsd" title="MDAnalysis.analysis.align.rmsd"><tt class="xref py py-func docutils literal"><span class="pre">rmsd()</span></tt></a> calculates the RMSD between <em>a</em> and <em>b</em>; for
fitting a whole trajectory it is more efficient to use
<a class="reference internal" href="#MDAnalysis.analysis.align.rms_fit_trj" title="MDAnalysis.analysis.align.rms_fit_trj"><tt class="xref py py-func docutils literal"><span class="pre">rms_fit_trj()</span></tt></a>. A complete fit of two structures can be
done with <a class="reference internal" href="#MDAnalysis.analysis.align.alignto" title="MDAnalysis.analysis.align.alignto"><tt class="xref py py-func docutils literal"><span class="pre">alignto()</span></tt></a>.</p>
</div>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="contacts.html" title="3.2. Native contacts analysis — MDAnalysis.analysis.contacts"
             >next</a> |</li>
        <li class="right" >
          <a href="../analysis_modules.html" title="3. Analysis modules"
             >previous</a> |</li>
        <li><a href="../../index.html">MDAnalysis v0.7.5-devel documentation</a> &raquo;</li>
          <li><a href="../analysis_modules.html" >3. Analysis modules</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2005-2011, Naveen Michaud-Agrawal, Elizabeth J. Denning, Joshua Adelman,
    Christian Beckstein (logo), David Caplan, Jan Domański, Philip Fowler,
    Joseph Goose, Benjamin Hall, Danny Parton, Tyler Reddy, Paul Rigor,
    and Oliver Beckstein.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
  </body>
</html>